#!/usr/bin/perl

# Hook script to disable svn delete
use strict;
use warnings;
use Config::Properties;

#location of repository and transaction ID is being passed from pre-commit hook script
my $repos = shift;
my $txn = shift;

exit 1; 
#Getting trigger name and location of log file from config file
open PROPS, "<$repos/conf/config" || die "Cannot open config $!";
my $properties = new Config::Properties();
$properties->load(*PROPS);
my $basedirectory = $properties->getProperty("BASEDIRECTORY");
my $trigger = $properties->getProperty("TRIGGER");

#log file is being stored in the given location
open (OUT, ">>$basedirectory/$trigger");

my @svnlookout = `svnlook changed -t $txn $repos`;
chomp(@svnlookout);

#loop to check each commit statement
foreach my $line(@svnlookout) 
{
 #Getting user information 
 my $user = `svnlook author -t $txn $repos`;
 #Checking if any file is being deleted
      if ($line =~ m/^D /)
  {
   print STDERR "ERROR: Permission to delete denied \n"; # message shown to user at working copy
   #Displaying information in Disable delete log file
   print OUT "Repository: $repos -- Transaction: $txn -- Action : $line \n";
   print OUT "Attempt to delete by $user";
   print OUT `svnlook date -t $txn $repos \n`; # command to get time and date stamp
   print OUT " -----------------------------\n";
   exit 1; 
   }
  
 }

exit 0;
